

import matplotlib.pyplot as plt
import tempfile

class DrawGraph:
    def __init__(self):

        self.title: str = None
        
        plt.style.use('dark_background')
        
        self.point_cord_x: list = None
        self.point_cord_y: list = None
        
        self.line_cord_x: list = None
        self.line_cord_y: list = None
        
        self.min = (None, None)
        self.max = (None, None)
    
    def _draw_graph(self):
        plt.clf() # Clear Plot
        
        # Draw Point:
        if self.point_cord_x and self.point_cord_y:
            plt.scatter(self.point_cord_x, self.point_cord_y, color='red', label='Point', marker=".")
        # Draw Line:
        if self.line_cord_x and self.line_cord_y:
            plt.plot(self.line_cord_x, self.line_cord_y, linestyle='--', color='cyan', label='Line')

        plt.title(self.title)
        plt.xlabel('X')
        plt.ylabel('Y')
        plt.legend()

        plt.grid(color='#222222', linestyle='--',)

        plt.xlim(self.min)
        plt.ylim(self.min)

    def get_graph(self) -> str:
        """Returned graph name"""
        
        self._draw_graph()
        
        with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as temp_file:
            plt.savefig(temp_file.name)
            return temp_file.name
        
    def show_graph(self):
        self._draw_graph()
        
        plt.show()

